package org.example.springboot.jpa.service.impl;

import org.example.springboot.jpa.po.User;
import org.example.springboot.jpa.repository.UserRepository;
import org.example.springboot.jpa.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.transaction.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Resource
    private UserRepository userRepository;

    @Override
    public User getUserById(String id) {
        User user = userRepository.findById(id).get();
        return user;
    }

    @Override
    public User authenticate(String username, String password) {
        User user = userRepository.findByLoginName(username);
        if (user.getPassword().equals(password)) {
            return user;
        }
        return null;
    }
}
